<template>
  <div>
   <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave" v-if="list.length > 0">
      <div class="mb-[10px] page"   >
        <div style="margin-top: 10px;" v-for="(item,index) in  list">
           <el-card shadow="hover">
              <AccItem :item="item" @flushAccount="flushAccount"></AccItem>
           </el-card>
         </div>

         <!--
         <div style="margin-top: 10px;">
           <el-card shadow="hover">
              <AccItem></AccItem>
           </el-card>
         </div>-->
      </div>
    </transition>
     <el-empty description="暂无账户数据" v-if="list.length == 0"/>
     </div>
</template>

<script setup name="incomBa" lang="ts">
  import {operatorAccount,operatorAccountDetail,channelAccount,channelAccountDetail,sydAccount,sydAccountDetail} from "@/api/operator/incomBa";
  import AccItem from "@/components/accItem/accItem.vue";
  import ServiceTx from "./cashout/serviceTx.vue"
  import AgentTx from "./cashout/agentTx.vue"
  import useUserStore from '@/store/modules/user'
  const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  //
  const list = ref([]);
  const userRole = ref(0);
   /**
    * 查询账户列表
    */
   const getList = () => {
     const elLoading = ElLoading.service({ fullscreen: false ,target:'.page'});
     if(userRole.value == 7){
       //运营商
       operatorAccount({}).then(res => {
         list.value = res.rows
       }).finally(()=>{
         elLoading.close();
       })
     }else if(userRole.value == 8){
       //代理商
       channelAccount({}).then(res => {
         list.value = res.rows
       }).finally(()=>{
         elLoading.close();
       })
     }else if(userRole.value == 6){
       //服务商
       sydAccount({}).then(res => {
         list.value = res.rows
       })
     }else{
      elLoading.close();
     }

   }


  //刷新余额
   const flushAccount = (item:any)=>{
      const elLoading = ElLoading.service({ fullscreen: false ,target:'.page'});
      if(userRole.value == 7){
        //运营商
        operatorAccountDetail(item.item.id).then(res=>{
          let data = res.data;
          let i = 0 ;
          for( let l of list.value){
              if(l.id == data.id){

                  list.value[i] = data;
                  break;
              }
              i++;
          }}).finally(()=>{
        elLoading.close();
      });
      }else if(userRole.value == 8){
        //代理商
       channelAccountDetail(item.item.id).then(res=>{
         let data = res.data;
         let i = 0 ;
         for( let l of list.value){
             if(l.id == data.id){
                 data.bankCard = list.value[i].bankCard;
                 data.channelName = list.value[i].channelName;
                 list.value[i] = data;
                 break;
             }
             i++;
         }}).finally(()=>{
        elLoading.close();
      });
      }else if(userRole.value == 6){
        //服务商
        sydAccountDetail(item.item.id).then(res=>{
          let data = res.data;
          let i = 0 ;
          for( let l of list.value){
              if(l.id == data.id){
                  list.value[i] = data;
                  break;
              }
              i++;
          }
          console.log(list.value);
        }).finally(()=>{
          elLoading.close();
        });
      }
   }



   onMounted(() => {
     let curRoleId = useUserStore().curRoleId;
     userRole.value = curRoleId;
      getList();
    });


</script>

<style>

 .page{

   height:100vh;
   background: #f0f2f5;
   min-width: 1200px;
   margin-top: 5px;
   margin-left: 5px;
   margin-right: 5px;

 }

 .el-card__body {
     padding:0
 }


</style>
